<template>
  <drop-wrap :data="data" :index="index" :element="element">
    <el-form-item
      :id="element.cid"
      :prop="prop"
      :rules="rules"
      :label="element.options.label"
    >
      <el-input
        type="textarea"
        v-model="element.options.defaultValue"
        @change="change"
        v-bind="inputAttrs"
      ></el-input>
    </el-form-item>
  </drop-wrap>
</template>

<script>
import { ruleCheck } from "@/low-code/utils/store.js";
import { fieldType, ruleCheckOringin } from "@/low-code/utils/enumeration.js";
export default {
  props: ["element", "data", "index"],
  data() {
    return {
      fieldType,
    };
  },
  methods: {
    change() {},
  },
  computed: {
    prop() {
      return `${this.element.fullModelTag}`;
    },
    store() {
      return this.element.getRoot();
    },
    inputAttrs() {
      const attrsConfig = {
        [this.fieldType.TEXT]: {
          maxlength: this.element.options.fieldLength,
          showWordLimit: true,
        },
        [this.fieldType.NUMBER]: {
          max: this.element.options.fieldLength,
          showWordLimit: true,
          type: this.element.options.fieldType,
        },
      };
      // console.log('attrsConfig', attrsConfig)
      return Object.assign(
        {
          readonly: this.element.options.readonly,
          disabled: this.element.options.disabled,
          clearable: this.element.options.clearable,
          placeholder: this.element.options.placeholder,
        },
        attrsConfig[this.element.options.fieldType]
      );
    },
    rules() {
      let _this = this;
      const rules = [{ validator: ruleCheck.noCheck(), trigger: "blur" }];
      this.element.rules.map((item) => {
        if (item.ruleType == ruleCheckOringin.SELECT) {
          item.validator = ruleCheck.validatePass(item.validatorType);
          rules.push(item);
        } else {
          rules.push({
            validator:function (rule, value, callback){
              let form= _this.store.models
              item.validator&&eval(item.validator)(rule, value, callback,form);
            },
            trigger: "blur",
          });
        }
      });
      return rules;
    },
  },
};
</script>